package com.bosssoft.cloud.wechat.core.api.impl;

import cn.hutool.core.bean.BeanUtil;
import com.bosssoft.cloud.wechat.core.api.MenuService;
import com.bosssoft.cloud.wechat.core.api.SignatureService;
import com.bosssoft.cloud.wechat.core.bean.WxApiBaseR;
import com.bosssoft.cloud.wechat.core.bean.menu.WxMenuInfo;
import com.bosssoft.cloud.wechat.core.bean.menu.WxMenuParam;
import com.bosssoft.cloud.wechat.core.infra.enums.WxApiUrl;
import com.bosssoft.cloud.wechat.infrastructure.client.OkClient;
import com.bosssoft.cloud.wechat.infrastructure.enums.ErrEnum;
import com.bosssoft.cloud.wechat.infrastructure.util.Assert;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import static com.bosssoft.cloud.wechat.infrastructure.constant.WxKeywordConsts.WX_RESULT_SUCCESS;

/**
 * @author wcy create on 2021/7/7 10:39 上午
 */
@Slf4j
@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    private SignatureService signatureService;

    @Resource
    private OkClient okClient;


    @Override
    public void create(WxMenuParam param) {
        WxApiBaseR res = okClient.newClient(WxApiBaseR.class)
                .runWx(BeanUtil.toBean(param, WxMenuInfo.class), WxApiUrl.Menu.MENU_CREATE, signatureService.getAccessToken())
                .execute();
        Assert.isTrue(res.getErrcode().equals(WX_RESULT_SUCCESS), ErrEnum.C0641, res.toString());
    }

    @Override
    public void create(String url) {
    }
}
